package com.unitech.drinks.controller;

import com.unitech.drinks.controller.param.PageParam;
import com.unitech.drinks.model.Drink;
import com.unitech.drinks.service.DrinkService;
import com.unitech.drinks.vo.ResponsePageDrinks;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
public class DrinkController {

    @Autowired
    private DrinkService drinkService;

    //分页 列出所有饮品
    @GetMapping(path = "/drink")
    @ResponseStatus(code = HttpStatus.OK)
    public ResponsePageDrinks listDrinksAll(@RequestBody @Valid PageParam pager) {
        return drinkService.listDrinks(pager.getPage(), pager.getSize());
    }


    //查询指定id的饮品
    @GetMapping(path = "/drink/{id}")
    @ResponseStatus(code = HttpStatus.OK)
    public Drink showDrinkOne (@PathVariable Integer id) {
        return drinkService.showDrinkOne(id);
    }



//    创建饮品
    @PostMapping(path = "/drink/")
    public Drink createDrink(@RequestBody @Valid Drink drink) {
        return drinkService.createDrink(drink);
    }

//    修改饮品
    @PutMapping(path = "/drink/")
    public Drink modifyDrink(@RequestBody @Valid Drink drink) {
        return drinkService.modifyDrink(drink);
    }

//    删除饮品
    @DeleteMapping(path =  "/drink/{id}")
    public String deleteDrink(@PathVariable Integer id) {
        drinkService.deleteDrink(id);
        return "删除成功";

    }
}
